download_java_rpm() {
  exec_cmd "curl -o '$1' ${JAVA_DOWNLOAD_URL}"

  if [ ! -f $1 ]; then
    print_status "${red}${JAVA_PATH} non-exists.${normal}"
    bail
  fi;
}

install_java() {
  JAVA_PATH="${APP_PATH}/${JAVA_RPM_VERSION}";

  # 判断java/jdk是否安装，未安装则安装java
  if [ "X`echo ${JAVA_EXISTING} | sh`" != "X" ]; then
    print_status "${green}[java] was installed.${normal}"
  else
    download_java_rpm ${JAVA_PATH}
    exec_cmd "rpm -ivh ${JAVA_PATH} && rm -f ${JAVA_PATH}"
  fi;
  unset JAVA_PATH
}

update_java() {
  JAVA_PATH="${APP_PATH}/${JAVA_RPM_VERSION}";

  JAVA_CURRENT_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }'`
  if [ "${JAVA_CURRENT_VERSION}" != "${JAVA_VERSION}" ]; then
    download_java_rpm ${JAVA_PATH}
    exec_cmd "rpm -Uvh ${JAVA_PATH} && rm -f ${JAVA_PATH}"
  else
    print_status "${green}[java] current version ${JAVA_CURRENT_VERSION}.${normal}"
  fi;
  unset JAVA_CURRENT_VERSION
  unset JAVA_PATH
}

